WIP/proof-of-concept: refactor Box
/Rc
/Arc
to reduce code duplication.
#134
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIP/proof-of-concept: As mentioned in #132, much of the code for
Box
/Rc
/Arc
's functions is very similar. This WIP does not address the public API duplication mentioned in that PR and #133, but it does somewhat address the code duplication by factoring out the common code into generictry_cast_aligned_ptr
andtry_cast_aligned_slice_ptr
functions, which use a traitCastablePointer
to convert between smart pointer types and raw pointers.The API is the same as #132 and is all implemented, but there are some "TODO"s in the code of things that could be added or things that could be removed.
Currently, the only changes are private, but something similar this could perhaps be made public.
Alternately to how it currrently works, the
CastablePointer<T>
trait could instead be parameterized on the "raw" type it returns, (rather than being hardcoded to have a "raw" type of*mut T
). This could make it possible to additionally use it forVec
, though I don't know how useful that would be, sinceVec
needs some special handling anyway.